(function($) {
	$(function(event) {
		var
			mesReq = 'REQUIRED_FIELD'.translate(),
			mesPas = 'PASSWORDS_DONT_MATCH'.translate(),
			mesEmail = 'INCORRECT_EMAIL'.translate(),
			mesDay = 'CHOOSE_DAY'.translate(),
			mesMonth = 'CHOOSE_MONTH'.translate(),
			mesYear = 'CHOOSE_YEAR'.translate(),
			mesUrl		= 'INPUT_CORRECT_URL'.translate(),
			mesSer		= 'INPUT_SERIA'.translate(),
			mesNum		= 'INPUT_NUMBER'.translate(),
			mesAuthor	= 'INPUT_WHO_GIVED'.translate()
		;
		$.validator.messages.required = mesReq;
		$.validator.messages.url = mesUrl;
		$('#selector-city-upd').change(function() {
			if ($(this).val() == -1) {
				$('#no-city').rules('add', {required: true});
			} else {
				$('#no-city').rules('remove', 'required');
			}
		});

		// *******  Start of user, admin, manager  ********
		if ($('#frm-settings-edit').hasClass('frm-user') || $('#frm-settings-edit').hasClass('frm-admin') || $('#frm-settings-edit').hasClass('frm-manager')) {
			$('#frm-settings-edit').validate({
				errorClass: 'invalid',
				messages: {
					reNewPassword: {
						equalTo: mesPas
					},
					day: {
						required: mesDay
					},
					month: {
						required: mesMonth
					},
					year: {
						required: mesYear
					},
					passport_issue_day: {
						required: mesDay
					},
					passport_issue_month: {
						required: mesMonth
					},
					passport_issue_year: {
						required: mesYear
					},
					passport_serial: {
						required: mesSer
					},
					passport_number: {
						required: mesNum
					}
				},
				rules: {
					reNewPassword: {
						equalTo: 'input[name="newPassword"]'
					}
				},
				errorPlacement: function(error, element) {
					if (element.attr("name") == "day" || element.attr("name") == "month" || element.attr("name") == "year")
						error.appendTo(".birthday-place-holder");
					else if (element.attr("name") == "passport_issue_day" || element.attr("name") == "passport_issue_month" || element.attr("name") == "passport_issue_year")
						error.appendTo(".date-passport-accept");
					else if (element.attr("name") == "passport_serial" || element.attr("name") == "passport_number")
						error.appendTo(".passport-serial");
					else
						error.insertAfter(element);
				}
			});
		}
		// *******  End of user, admin, manager  ********

		// *******  Start of agency, operator  ********
		if ($('#frm-settings-edit').hasClass('frm-agency') || $('#frm-settings-edit').hasClass('frm-operator')) {
			$('#frm-settings-edit').validate({
				errorClass: 'invalid',
				messages: {
					reNewPassword: {
						equalTo: mesPas
					},
					day: {
						required: mesDay
					},
					month: {
						required: mesMonth
					},
					year: {
						required: mesYear
					},
					license_serial: {
						required: mesSer
					},
					license: {
						required: mesNum
					},
					license_issue_day: {
						required: mesDay
					},
					license_issue_month: {
						required: mesMonth
					},
					license_issue_year: {
						required: mesYear
					},
					guarantee: {
						required: mesSer
					},
					guarantee_issue_agency: {
						required: mesNum
					},
					guarantee_issue_day: {
						required: mesDay
					},
					guarantee_issue_month: {
						required: mesMonth
					},
					guarantee_issue_year: {
						required: mesYear
					}
				},
				rules: {
					reNewPassword: {
						equalTo: 'input[name="newPassword"]'
					}
				},
				errorPlacement: function(error, element) {
					if (element.attr("name") == "license_serial" || element.attr("name") == "license" || element.attr("name") == "license_issue_day" || element.attr("name") == "license_issue_month" || element.attr("name") == "license_issue_year")
						error.appendTo(".licence-data-place-holder");
					else if (element.attr("name") == "guarantee" || element.attr("name") == "guarantee_issue_agency" || element.attr("name") == "guarantee_issue_day" || element.attr("name") == "guarantee_issue_month" || element.attr("name") == "guarantee_issue_year")
						error.appendTo(".guarantee-issue-place-holder");
					else
						error.insertAfter(element);
				}
			});
		}
		// *******  End of agency, operator  ********

		// *******  Start of agent, corporation  ********
		if ($('#frm-settings-edit').hasClass('frm-agent') || $('#frm-settings-edit').hasClass('frm-corporation')) {
			$('#frm-settings-edit').validate({
				errorClass: 'invalid',
				messages: {
					reNewPassword: {
						equalTo: mesPas
					},
					day: {
						required: mesDay
					},
					month: {
						required: mesMonth
					},
					year: {
						required: mesYear
					},
					passport_issue_day: {
						required: mesDay
					},
					passport_issue_month: {
						required: mesMonth
					},
					passport_issue_year: {
						required: mesYear
					},
					passport_serial: {
						required: mesSer
					},
					passport_number: {
						required: mesNum
					}
				},
				rules: {
					reNewPassword: {
						equalTo: 'input[name="newPassword"]'
					}
				},
				errorPlacement: function(error, element) {
					if (element.attr("name") == "day" || element.attr("name") == "month" || element.attr("name") == "year")
						error.appendTo(".birthday-place-holder");
					else if (element.attr("name") == "passport_issue_day" || element.attr("name") == "passport_issue_month" || element.attr("name") == "passport_issue_year")
						error.appendTo(".date-passport-accept");
					else if (element.attr("name") == "passport_serial" || element.attr("name") == "passport_number")
						error.appendTo(".passport-serial");
					else
						error.insertAfter(element);
				}
			});
		}
		// *******  End of agent, corporation  ********

		// *******  Start of agent-business  ********
		if ($('#frm-settings-edit').hasClass('frm-agent-business')) {
			$('#frm-settings-edit').validate({
				errorClass: 'invalid',
				messages: {
					reNewPassword: {
						equalTo: mesPas
					}
				},
				rules: {
					reNewPassword: {
						equalTo: 'input[name="newPassword"]'
					}
				},
				errorPlacement: function(error, element) {
					error.insertAfter(element);
				}
			});
		}
		// *******  End of agent-business  ********
	});
})(jQuery);